package kr.ac.kookmin.cs.random;

import kr.ac.kookmin.cs.randomtest.RandomNumberSequenceGenerator;

public class WELL512 extends RandomNumberSequenceGenerator {

	private static long[] state = new long[16];
	private static int index = 0;
	
	@Override
	public void initialize(long seed){
		super.initialize(seed);
		
		for(int i = 0 ; i < 16 ; i++){
			//state[i] = 0x00000000ffffffffL & new Random().nextInt();
			state[i] = seed+(i*73);
		}
	}
	
	@Override
	protected long getNextRandomNumber() {
		
		long a, b, c, d;
		
		a = state[index];
        c = state[(index + 13) & 15];
        b = 0xffffffffL & (a ^ c ^ (a << 16) ^ (c << 15));
        c = state[(index + 9) & 15];
        c ^= (c >>> 11);
        a = state[index] = b ^ c;
        d = a ^ ((a << 5) & 0x00000000da442d24L);
        index = (index + 15) & 15;
        a = state[index];
        state[index] = 0xffffffffL & (a ^ b ^ d ^ (a << 2) ^ (b << 18) ^ (c << 28));

        return state[index];
        
	}

	@Override
	protected long getRandomNumberWithSeed(long seed) {
		initialize(seed);
		return getNextRandomNumber();
	}
	
	public static void main(String[] args){
		WELL512 well512 = new WELL512();
		well512.initialize(1);
		
		for(int i = 0 ; i < 100 ; i++){
			System.out.println(well512.getNextRandomNumber());
		}
	}

}
